package ru.st.selenium;

import org.testng.annotations.Test;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.testng.*;
import org.testng.annotations.*;
import org.testng.*;

import static org.hamcrest.CoreMatchers.*;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public class LoginTest extends ru.st.selenium.pages.TestBase {

  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Test
  public void LoginTest() throws Exception {
	driver.get(baseUrl + "/php4dvd/");
    
	WebElement usernameField = driver.findElement(By.id("username"));
    usernameField.clear();
    usernameField.sendKeys("admin");
    
    WebElement passwordField = driver.findElement(By.name("password"));
    passwordField.clear();
    passwordField.sendKeys("admin");
    
    driver.findElement(By.name("submit")).click();
   }

  @Test  
  public void testCreateFailed() throws Exception {
	  driver.get(baseUrl + "/php4dvd/");
	  driver.findElement(By.cssSelector("img[alt=\"Add movie\"]")).click();
	  driver.findElement(By.id("submit")).click();
	  driver.findElement(By.className("error"));
  }
  
  @Test
  public void testSuccess() throws Exception {
	  driver.get(baseUrl + "/php4dvd/");
	  driver.findElement(By.cssSelector("img[alt=\"Add movie\"]")).click();
	  
	  WebElement nameField = driver.findElement(By.name("name"));
	  nameField.clear();
	  nameField.sendKeys("Film");
	  
	  WebElement yearField = driver.findElement(By.name("year"));
	  yearField.clear();
	  yearField.sendKeys("2014");
	  
	  driver.findElement(By.id("submit")).click();
  }

 @Test
 public void testSuccess2() throws Exception {
	  driver.get(baseUrl + "/php4dvd/");
	  driver.findElement(By.cssSelector("img[alt=\"Add movie\"]")).click();
	  
	  WebElement nameField = driver.findElement(By.name("name"));
	  nameField.clear();
	  nameField.sendKeys("AnotherFilm");
	  
	  WebElement yearField = driver.findElement(By.name("year"));
	  yearField.clear();
	  yearField.sendKeys("2014");
	  
	  driver.findElement(By.id("submit")).click();
 }
}


